package com.deer.wms.ware.task.model.pickTask;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.deer.wms.inventory.model.Inventory.InventorySelectDto;
import com.deer.wms.ware.task.constant.WareTaskConstant;
import com.deer.wms.ware.task.model.SO.SoDetail;
import com.deer.wms.ware.task.model.SO.SoMaster;
import com.deer.wms.ware.task.model.Wave.WaveDetail;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;

/**
 * @author guo
 */
@Getter
@Setter
@NoArgsConstructor
@Table(name = "pick_task")
public class PickTask {
    /**
     * 主键
     */
    @Id
    @TableId(type = IdType.AUTO)
    @Column(name = "pick_task_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer pickTaskId;

    /**
     * 拣货任务号
     */
    private String pickTaskCode;

    /**
     * 状态<p>
     *     0-已分配  1-部分拣货 2-已拣货 4-被合并  5-已经发货
     */
    private Integer state;

    /**
     * 父id  可能跟波次相关??
     */
    private Integer parentTaskId;

    /**
     * SO明细id
     */
    @Column(name = "so_detail_id")
    private Integer soDetailId;

    /**
     * SO单据id
     */
    @Column(name = "so_master_id")
    private Integer soMasterId;

    private String soMasterCode;

    /**
     * 波次明细ID
     */
    private Integer waveDetailId;

    /**
     * 波次号
     */
    private String waveCode;

    /**
     * 出库单号
     */
    private Integer outDetailId;

    private String outMasterCode;

    /**
     * 仓库id
     */
    @Column(name = "ware_id")
    private Integer wareId;

    /**
     * 仓库名
     */
    @Column(name = "ware_name")
    private String wareName;

    /**
     * 货主id
     */
    @Column(name = "organization_id")
    private Integer organizationId;

    /**
     * 货主名
     */
    @Column(name = "organization_name")
    private String organizationName;

    /**
     * 库区编码
     */
    @Column(name = "area_code")
    private String areaCode;

    /**
     * 库区名
     */
    @Column(name = "area_name")
    private String areaName;

    /**
     * 货位组编码
     */
    @Column(name = "shelf_code")
    private String shelfCode;

    /**
     * 货位组名
     */
    @Column(name = "shelf_name")
    private String shelfName;

    /**
     * 库位编码
     */
    @Column(name = "cell_code")
    private String cellCode;

    /**
     * 库位名
     */
    @Column(name = "cell_name")
    private String cellName;

    /**
     * 物料编码
     */
    @Column(name = "item_code")
    private String itemCode;

    /**
     * 物料名
     */
    @Column(name = "item_name")
    private String itemName;

    private String imgUrl;

    /**
     * 批次id
     */
    @Column(name = "batch_id")
    private Integer batchId;

    /**
     * 批次号
     */
    @Column(name = "batch_name")
    private String batchName;

    /**
     * 容器编码
     */
    @Column(name = "box_code")
    private String boxCode;

    /**
     * 目标容器编码 分拣的情况
     */
    private String toBoxCode;

    private String lpn;

    /**
     * 单位id
     */
    @Column(name = "pack_detail_id")
    private Integer packDetailId;

    /**
     * 单位描述
     */
    @Column(name = "pack_describe")
    private String packDescribe;

    /**
     * 计划数量
     */
    @Column(name = "pick_quantity")
    private Double pickQuantity;

    /**
     * 已拣货数量
     */
    private Double reviewQuantity;

    /**
     * 库存id
     */
    @Column(name = "inventory_id")
    private Integer inventoryId;

    private Integer toInventoryId;

    /**
     * ???
     */
    @Column(name="source")
    private Integer source;

    /**
     * ??
     */
    @Column(name="to_cell_code")
    private String toCellCode;

    /**
     * ???
     */
    @Column(name="tracking_num")
    private String trackingNum;

    @Column(name="pick_time")
    private String pickTime;

    @Column(name="pick_user_id")
    private Integer pickUserId;

    @Column(name="pick_user_name")
    private String pickUserName;

    @Column(name="check_time")
    private String checkTime;

    @Column(name="check_user_id")
    private Integer checkUserId;

    @Column(name="check_user_name")
    private String checkUserName;

    @Column(name="delivery_time")
    private String deliveryTime;

    @Column(name="delivery_user_id")
    private Integer deliveryUserId;

    @Column(name="delivery_user_name")
    private String deliveryUserName;

    /**
     * 备注
     */
    @Column(name="memo")
    private String memo;

    private Double seededQuantity;

    private Integer isParent;

    /**
     * 创建时间
     */
    @Column(name = "create_time")
    private String createTime;

    public PickTask(Integer soDetailId, Integer soMasterId, Integer wareId, String wareName, Integer organizationId, String organizationName, String areaCode, String areaName, String shelfCode, String shelfName, String cellCode, String cellName, String itemCode, String itemName, Integer batchId, String batchName, String boxCode, String lpn, Integer packDetailId, String packDescribe, Double pickQuantity, Integer state, Integer inventoryId,Integer source,String imgUrl) {
        this.soDetailId = soDetailId;
        this.soMasterId = soMasterId;
        this.wareId = wareId;
        this.wareName = wareName;
        this.organizationId = organizationId;
        this.organizationName = organizationName;
        this.areaCode = areaCode;
        this.areaName = areaName;
        this.shelfCode = shelfCode;
        this.shelfName = shelfName;
        this.cellCode = cellCode;
        this.cellName = cellName;
        this.itemCode = itemCode;
        this.itemName = itemName;
        this.batchId = batchId;
        this.batchName = batchName;
        this.boxCode = boxCode;
        this.lpn = lpn;
        this.packDetailId = packDetailId;
        this.packDescribe = packDescribe;
        this.pickQuantity = pickQuantity;
        this.state = state;
        this.inventoryId = inventoryId;
        this.source = source;
        this.imgUrl = imgUrl;

    }

    public PickTask(Integer soDetailId, Integer soMasterId, Integer wareId, String wareName, Integer organizationId, String organizationName,    String cellCode,   String itemCode, String itemName, Integer batchId, String batchName, String boxCode, String lpn, Integer packDetailId, String packDescribe, Double pickQuantity, Integer state, Integer inventoryId,Integer source,String imgUrl) {
        this.soDetailId = soDetailId;
        this.soMasterId = soMasterId;
        this.wareId = wareId;
        this.wareName = wareName;
        this.organizationId = organizationId;
        this.organizationName = organizationName;

        this.cellCode = cellCode;
        this.itemCode = itemCode;
        this.itemName = itemName;
        this.batchId = batchId;
        this.batchName = batchName;
        this.boxCode = boxCode;
        this.lpn = lpn;
        this.packDetailId = packDetailId;
        this.packDescribe = packDescribe;
        this.pickQuantity = pickQuantity;
        this.state = state;
        this.inventoryId = inventoryId;
        this.source = source;
        this.imgUrl = imgUrl;
    }

    public PickTask(WaveDetail waveDetail) {
        this.soDetailId = waveDetail.getSoDetailId();
//        this.soMasterId = waveDetail.getSoMasterId();  soMaster
        this.wareId = waveDetail.getWareId();
        this.wareName = waveDetail.getWareName();
        this.itemCode = waveDetail.getItemCode();
        this.itemName = waveDetail.getItemName();
        this.packDetailId = waveDetail.getPackDetailId();
        this.packDescribe = waveDetail.getPackDescribe();
        this.state = WareTaskConstant.PICK_STATE_PROCESSING;
        this.waveDetailId = waveDetail.getWaveDetailId();
        this.waveCode = waveDetail.getWaveCode();
        this.source  = 2;
    }

    public PickTask(SoMaster soMaster, SoDetail soDetail, InventorySelectDto invDto) {
        this.soMasterId = soMaster.getSoMasterId();
        this.soMasterCode = soMaster.getBillNo();
        this.wareId = soMaster.getWareId();
        this.wareName = soMaster.getWareName();
        this.organizationId = soMaster.getOrganizationId();
        this.organizationName = soMaster.getOrganizationName();

        this.soDetailId = soDetail.getSoDetailId();
        this.packDetailId = soDetail.getPackDetailId();
        this.packDescribe = soDetail.getPackDescribe();
        this.pickQuantity = 0.0;
        this.reviewQuantity = 0.0;
        this.seededQuantity = 0.0;
        this.itemName = soDetail.getItemName();
        this.itemCode = soDetail.getItemCode();
        this.state = WareTaskConstant.PICK_STATE_PROCESSING;

        this.areaCode = invDto.getAreaCode();
        this.areaName = invDto.getAreaName();
        this.shelfCode = invDto.getShelfCode();
        this.shelfName = invDto.getShelfName();
        this.cellCode = invDto.getCellCode();
        this.cellName = invDto.getCellName();
        this.batchId = invDto.getBatchId();
        this.batchName = invDto.getBatchName();
        this.boxCode = invDto.getBoxCode();
        this.inventoryId = invDto.getInventoryId();

        this.createTime = DateUtil.now();
    }
}